using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "TargetNearestEnemySoldier-获得最近的敌方士兵", menuName = "Skill/Target/TargetNearestEnemySoldier-获得最近的敌方士兵")]
public class TargetNearestEnemySoldier : TargetSelectorBase
{
    public override List<Chess> SelectTargets(Chess chess, GameEvent e)
    {
        var list = ChessManager.GetInstance().chessList;
        var targetList = new List<Chess>();
        float distance = 0;
        foreach (var c in list)
        {
            if(c.GetChessSide() == chess.GetChessSide() || c.chessDate.chessType != ChessType.Soldier) continue;
            var d = CalculateDistance(c.ChessDetail.Position, chess.ChessDetail.Position);
            if (d < distance)
            {
                distance = d;
                targetList[0] = c;
            }
        }


        return targetList;
    }
        
        
    float CalculateDistance(Vector2Int a, Vector2Int b)
    {
        int dx = b.x - a.x;
        int dy = b.y - a.y;
        return Mathf.Sqrt(dx * dx + dy * dy);
    }
}